package com.zhs.xyzsdk.editors;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.ui.editors.text.FileDocumentProvider;

import com.zhs.xyzsdk.builder.XYZBuilder;
import com.zhs.xyzsdk.builder.XYZNature;
import com.zhs.xyzsdk.editors.token.TokenManager;

import org.eclipse.ui.part.FileEditorInput;

public class XYZDocumentProvider extends FileDocumentProvider {

	protected IDocument createDocument(Object element) throws CoreException {
		String name=element.getClass().toString();
		FileEditorInput fei=(FileEditorInput)element;
		IFile file = fei.getFile();
		new XYZBuilder().checkXYZ(file);
		IDocument document = super.createDocument(element);
		if (document != null) {
			IDocumentPartitioner partitioner = new FastPartitioner(
					new XYZPartitionScanner(), new String[0]);
			partitioner.connect(document);
			document.setDocumentPartitioner(partitioner);
		}
		TokenManager.registerDocument(document);
		return document;
	}
}
